<template>
	<view>
		<stop isBack>
			<view slot="content">创建总结计划</view>
		</stop>
		<view class="mart3">
			<sentity model="CimingReportType" v-model="en.type" label="计划类型" placeholder="请选择计划类型"></sentity>
		</view>
		<view class="mart3 bdbso">
			<stab :names="['总结','计划','往期数据(近10期)']" v-model="myCurTab"></stab>
		</view>
		<!-- 工作总结	 -->
		<view class="bcf pad3" v-show="myCurTab == 0">
			<view class="list-style-2">工作总结</view>
			<view class="mart3">
				<view class="bdso mart3 round3" v-for="(item,index) in en.summary" :key="item[2]">
					<view class="flex-r flex-end">
						<view class="fs16 fwb padl4 flex1">{{index+1}}.</view>
						<view class="flrc">
							<view class="flex1 cu-btn text-green" @tap="copyIt(item[0],'summary')">
								<text>复制内容</text>
								<ripple></ripple>
							</view>
							<view class="flex1 cu-btn marl1 text-orange" @tap="pastIt(index,'summary')">
								<text>粘贴内容</text>
								<ripple></ripple>
							</view>
							<view class="flex1 cu-btn marl1 text-red" @tap="deleteIt(index,'summary')">
								<text>删除本条</text>
								<ripple></ripple>
							</view>
						</view>
					</view>
					<view>
						<stext label="内容" placeholder="工作内容" v-model="item[0]"></stext>
					</view>
					<view>
						<sentity label="进度" placeholder="选择进度" model="CimingReportItemStatus" v-model="item[1]"></sentity>
					</view>
					<view class="text-orange pad2 fs7">
						*注：进度选择优先使用量化进度，10%-100%，无法量化则使用状态描述
					</view>
				</view>
				<view class="mar3 pad5 tac bdda tac fs12 c12 bc13 pos-r" @tap="addSummary">
					添加一条
					<ripple></ripple>
				</view>
			</view>
		</view>
		<!-- 工作计划	 -->
		<view class="bcf pad3" v-show="myCurTab == 1">
			<view class="list-style-2">工作计划</view>
			<view class="mart3">
				<view class="bdso mart3 round3" v-for="(item,index) in en.plan" :key="item[2]">
					<view class="flex-r flex-end">
						<view class="fs16 fwb padl4 flex1">{{index+1}}.</view>
						<view class="flrc">
							<view class="flex1 cu-btn text-green" @tap="copyIt(item[0],'plan')">
								<text>复制内容</text>
								<ripple></ripple>
							</view>
							<view class="flex1 cu-btn marl1 text-orange" @tap="pastIt(index,'plan')">
								<text>粘贴内容</text>
								<ripple></ripple>
							</view>
							<view class="flex1 cu-btn marl1 text-red" @tap="deleteIt(index,'plan')">
								<text>删除本条</text>
								<ripple></ripple>
							</view>
						</view>
					</view>
					<view>
						<stext label="内容" placeholder="工作内容" v-model="item[0]"></stext>
					</view>
					<view>
						<sentity label="进度" placeholder="选择进度" model="CimingReportItemStatus" v-model="item[1]"></sentity>
					</view>

				</view>
				<view class="mar3 pad5 tac bdda tac fs12 c12 bc13 pos-r" @tap="addPlan">
					添加一条
					<ripple></ripple>
				</view>
			</view>
		</view>
		<!-- 往期数据 -->
		<view class="bcf pad3" v-show="myCurTab == 2">
			<view class="bdso mart3 round3 ofh" v-for="item in logs">
				<view class="bc13 c12 pad2 flrc">
					<view class="flex1 c11">{{datetime(item.createAt)}}</view>
					<view class="c11 fs10">{{item.type.name}}</view>
				</view>
				<!-- 总结 -->
				<view class="mart3 padl3">
					<view class="list-style-2 fwb">总结</view>
					<view v-for="row,index in item.summary" class="flex-r flex-start pad2 pos-r" @tap="copyIt(row[0])">
						<text class="fwb wh10-10 flcc bg-black">{{index+1}}.</text>
						<view>
							<view class="padl2">进度：{{row[1]}}</view>
							<view class="padl2">内容：{{row[0]}}</view>
						</view>
						<ripple></ripple>
					</view>
					<view class="mar2 pad3 bdso tac" v-show="item.summary.length == 0">内容未填写</view>
				</view>
				<!-- 计划 -->
				<view class="mart3 padl3">
					<view class="list-style-2 fwb">计划</view>
					<view v-for="row,index in item.plan" class="flex-r flex-start pad2 pos-r" @tap="copyIt(row[0])">
						<text class="fwb wh10-10 flcc bg-black">{{index+1}}.</text>
						<view>
							<view class="padl2">进度：{{row[1]}}</view>
							<view class="padl2">内容：{{row[0]}}</view>
						</view>
						<ripple></ripple>
					</view>
					<view class="mar2 pad3 bdso tac" v-show="item.plan.length == 0">内容未填写</view>
				</view>
				<!-- {{item}} -->
			</view>
		</view>
		<!-- 保存	 -->
		<view class="pos-f b0 l0 r0 pad3 bcf">
			<view class="cu-btn lg tac w100 round line-green" @tap="save">
				保存
				<ripple></ripple>
			</view>
			<view class="cu-btn lg tac w100 round line-red mart3" @tap="deleteEn" v-show="isbool(id)">
				删除
				<ripple></ripple>
			</view>
		</view>
		<loading :loading="myIsLoading"></loading>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:0,
				en: {
					type: '',
					summary: [],
					plan: [],
				},
				copyContent: '',
				logs:[]
			}
		},
		methods: {
			addSummary() {
				this.en.summary.push(['', '', Math.random()])
			},
			addPlan() {
				this.en.plan.push(['', '', Math.random()])
			},
			copyIt(item, who) {
				this.copyContent = item
				this.$com.showToast('内容已复制')
			},
			pastIt(index, who) {
				if (who === 'summary') {
					this.$set(this.en.summary[index], "0", this.copyContent)
				} else {
					this.$set(this.en.plan[index], "0", this.copyContent)
				}
			},
			deleteIt(index, who) {
				if (who === 'summary') {
					this.en.summary = this.$com.arrayDelIndex(this.en.summary, index)
				} else {
					this.en.plan = this.$com.arrayDelIndex(this.en.plan, index)
				}
			},
			save() {
				if(!this.isbool(this.en.type)){
					this.$com.showToast('请选择日志类型')
					return false
				}
				this.$api.put('/api/cimingReports',this.en,res=>{
					this.log(res)
					this.$com.showToast(res.i)
				})
			},
			deleteEn(){
				if(this.isbool(this.id)){
					this.$api.delete('/api/cimingReports/'+this.id,{},res=>{
						this.$win.goback()
					})
				}
			}
		},
		onLoad(option) {
			this.$api.get('/api/me/cimingReports',{
				_g:['report']
			},res=>{
				this.log(res)
				this.logs = res.d
			})
			if(option.id != undefined){
				this.id = option.id
				this.showLoading()
				this.$api.res('ciming_reports',option.id,res=>{
					this.log(res)
					this.en = res
					this.clearLoading()
				})
			}else{
				setTimeout(this.clearLoading,300)
			}
		}

	}
</script>

<style>

</style>
